﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace ASBCC.Utility
{
    public sealed class ConfigUtility
    {
        private static AppSettingsReader appSettingsReader = new AppSettingsReader();
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static String ConnectionString
        {
            get
            {
                if (appSettingsReader.GetValue("ConnectionString", typeof(String)) != null
                    && appSettingsReader.GetValue("ConnectionString", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("ConnectionString", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取数据库连接字符串出错！");
                }
            }
        }
        /// <summary>
        /// WebApplication基础目录
        /// </summary>
        public static String ApplicationBasePath
        {
            get
            {
                if (appSettingsReader.GetValue("ApplicationBasePath", typeof(String)) != null
                    && appSettingsReader.GetValue("ApplicationBasePath", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("ApplicationBasePath", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取ApplicationBasePath出错！");
                }
            }
        }
        /// <summary>
        /// 是否使用LDAP
        /// </summary>
        public static bool EnableLDAPAudit
        {
            get
            {
                if (appSettingsReader.GetValue("EnableLDAPAudit", typeof(bool)) != null
                    && appSettingsReader.GetValue("EnableLDAPAudit", typeof(bool)).ToString() != String.Empty)
                {
                    return Convert.ToBoolean(appSettingsReader.GetValue("EnableLDAPAudit", typeof(bool)));
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取EnableLDAPAudit出错！");
                }
            }
        }
        /// <summary>
        /// 是否强制SSL登录
        /// </summary>
        public static bool ForceSecureLogin
        {
            get
            {
                if (appSettingsReader.GetValue("ForceSecureLogin", typeof(bool)) != null
                    && appSettingsReader.GetValue("ForceSecureLogin", typeof(bool)).ToString() != String.Empty)
                {
                    return Convert.ToBoolean(appSettingsReader.GetValue("ForceSecureLogin", typeof(bool)));
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取ForceSecureLogin出错！");
                }
            }
        }
        /// <summary>
        /// LDAP服务器地址
        /// </summary>
        public static String LDAPURL
        {
            get
            {
                if (appSettingsReader.GetValue("LDAPURL", typeof(String)) != null
                    && appSettingsReader.GetValue("LDAPURL", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("LDAPURL", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取LDAPURL出错！");
                }
            }
        }

        /// <summary>
        /// 上传路径
        /// </summary>
        public static String UploadPath
        {
            get
            {
                if (appSettingsReader.GetValue("UploadPath", typeof(String)) != null
                    && appSettingsReader.GetValue("UploadPath", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("UploadPath", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取LDAPURL出错！");
                }
            }
        }
        /// <summary>
        /// 上传路径
        /// </summary>
        public static String TemplatePath
        {
            get
            {
                if (appSettingsReader.GetValue("TemplatePath", typeof(String)) != null
                    && appSettingsReader.GetValue("TemplatePath", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("TemplatePath", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取LDAPURL出错！");
                }
            }
        }
        #region 文件上传

        /// <summary>
        /// 上传服务器IP
        /// </summary>
        public static String UploadServerIP
        {
            get
            {
                if (appSettingsReader.GetValue("UploadServerIP", typeof(String)) != null
                    && appSettingsReader.GetValue("UploadServerIP", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("UploadServerIP", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取UploadServerIP出错！");
                }
            }
        }

        /// <summary>
        /// 上传目录
        /// </summary>
        public static String UploadFolder
        {
            get
            {
                if (appSettingsReader.GetValue("UploadFolder", typeof(String)) != null
                    && appSettingsReader.GetValue("UploadFolder", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("UploadFolder", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取UploadFolder出错！");
                }
            }
        }

        /// <summary>
        /// 上传目录
        /// </summary>
        public static String EZVisitDocument
        {
            get
            {
                if (appSettingsReader.GetValue("EZVisitDocument", typeof(String)) != null
                    && appSettingsReader.GetValue("EZVisitDocument", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("EZVisitDocument", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取APDocument出错！");
                }
            }
        }

        /// <summary>
        /// 模板目录
        /// </summary>
        public static String TempletFolder
        {
            get
            {
                if (appSettingsReader.GetValue("TempletFolder", typeof(String)) != null
                    && appSettingsReader.GetValue("TempletFolder", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("TempletFolder", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取TempletFolder出错！");
                }
            }
        }

        /// <summary>
        /// 临时目录
        /// </summary>
        public static String TemporaryFolder
        {
            get
            {
                if (appSettingsReader.GetValue("TemporaryFolder", typeof(String)) != null
                    && appSettingsReader.GetValue("TemporaryFolder", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("TemporaryFolder", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取TemporaryFolder出错！");
                }
            }
        }

        /// <summary>
        /// 下载目录
        /// </summary>
        public static String DownLoadFilesFolder
        {
            get
            {
                if (appSettingsReader.GetValue("DownLoadFilesFolder", typeof(String)) != null
                    && appSettingsReader.GetValue("DownLoadFilesFolder", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("DownLoadFilesFolder", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取DownLoadFilesFolder出错！");
                }
            }
        }
        /// <summary>
        /// 域
        /// </summary>
        public static String FileServerDomain
        {
            get
            {
                if (appSettingsReader.GetValue("FileServerDomain", typeof(String)) != null)
                {
                    return appSettingsReader.GetValue("FileServerDomain", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取FileServerDomain出错！");
                }
            }
        }
        /// <summary>
        /// 域
        /// </summary>
        public static String FileServerLogin
        {
            get
            {
                if (appSettingsReader.GetValue("FileServerLogin", typeof(String)) != null
                    && appSettingsReader.GetValue("FileServerLogin", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("FileServerLogin", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取FileServerLogin出错！");
                }
            }
        }
        /// <summary>
        /// 域
        /// </summary>
        public static String FileServerPwd
        {
            get
            {
                if (appSettingsReader.GetValue("FileServerPwd", typeof(String)) != null
                    && appSettingsReader.GetValue("FileServerPwd", typeof(String)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("FileServerPwd", typeof(String)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取FileServerPwd出错！");
                }
            }
        }

        /// <summary>
        /// 发送者电子邮件地址
        /// </summary>
        public static string MailSender
        {
            get
            {
                if (appSettingsReader.GetValue("MailSender", typeof(string)) != null
                    && appSettingsReader.GetValue("MailSender", typeof(string)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("MailSender", typeof(string)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取MailSender出错！");
                }
            }
        }
        #endregion

        /// <summary>
        /// 允许上传的文件格式
        /// </summary>
        public static string AllowUploadFormat
        {
            get
            {
                if (appSettingsReader.GetValue("AllowUploadFormat", typeof(string)) != null
                    && appSettingsReader.GetValue("AllowUploadFormat", typeof(string)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("AllowUploadFormat", typeof(string)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取AllowUploadFormat出错！");
                }
            }
        }

        /// <summary>
        /// 允许上传的文件大小;单位M
        /// </summary>
        public static string AllowUploadMaxSize
        {
            get
            {
                if (appSettingsReader.GetValue("AllowUploadMaxSize", typeof(string)) != null
                    && appSettingsReader.GetValue("AllowUploadMaxSize", typeof(string)).ToString() != String.Empty)
                {
                    return appSettingsReader.GetValue("AllowUploadMaxSize", typeof(string)).ToString();
                }
                else
                {
                    throw new Exception("从配置文件Web.Config读取AllowUploadMaxSize出错！");
                }
            }
        }

        



    }
}
